<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let input = `4,5,6,7,0,1,2
        6,4,0,1,2,5,7`
        let spl = input.split('\n')
        let [in_list, out_list] = [spl[0].split(',').map(v => parseInt(v)), spl[1].split(',').map(v => parseInt(v))]

        // if(in_list.sort().toString()!==out_list.sort().toString()){
        //     console.log('NO');           
        // }else{
        //     console.log(1);  
        // }


        let list = [];//桶
        let in_t = in_list.length//总存数长度
        let i = 0//存列表的下标
        let res =''
        


        while (in_t > 0) {       
            list.push(in_list[i]);      

            if (out_list[0] === in_list[i]) {
                while(list.length>0&&(list[0]===out_list[0]||list[list.length-1]===out_list[0])){
                    
                    if(list.length>0&&list[0]===out_list[0]){
                        list.shift()
                        out_list.shift()
                        res+='L'                        
                    }
                    if(list.length>0&&list.length!=1&&list[list.length-1]===out_list[0]){
                        list.pop()
                        out_list.shift()
                        res+='R'                                            
                    }
                }

            }
            i++;
            in_t--;
        }

console.log(res);

    </script>
</body>

</html>